<?php
class retrieve_layout extends retrieve_base{

	private $module_display_options 	= array();

	/**
	* function produces abstract structure of modules db structure
	*
    * used to generate the table structure required abstract function that passes an abstract
	* representation of the desired table structure to the proper database module which will
	* interpet the abstract and convert it into a valid SQL Create table structure.
	*
	* @return Array list of abstract table definitions for this module
	*/
	function create_table(){
		$tables = array();
		/*
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		* menu data table
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		*/
		$fields = array(
			array("menu_identifier"			,"unsigned integer"			,"NOT NULL"	,"auto_increment"	,"key"),
			array("menu_client"				,"unsigned integer"			,"NOT NULL"	,"default '0'"	,"key"),
			array("menu_parent"				,"unsigned integer"			,"NOT NULL"	,"default '01'"	,"key"),
			array("menu_label"				,"varchar(255)"				,""			,"default NULL"),
			array("menu_alt_text"			,"varchar(255)"				,""			,"default NULL"),
			array("menu_url"				,"varchar(255)"				,"NOT NULL"	,"default ''"),
			array("menu_order"				,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("menu_ssl"				,"unsigned small integer"	,"NOT NULL"	,"default '0'"),
			array("menu_stylesheet"			,"unsigned integer"			,"NOT NULL"	,"default '2'"	,"key"),
			array("menu_sort"				,"unsigned integer"			,"NOT NULL"	,"default '1'"	,"key"),
			array("menu_theme"				,"unsigned integer"			,""			,"default '0'"	,"key"),
			array("menu_directory"			,"unsigned integer"			,""			,"default '0'"	,"key"),
			array("menu_hidden"				,"unsigned integer"			,""			,"default '0'"),
			array("menu_image_display"		,"unsigned small integer"	,""			,"default '0'"), // 0 left, 1 right, 2 alternatve 
			array("menu_headline_all"		,"unsigned small integer"	,""			,"default '0'"),
			array("menu_headline_content"	,"unsigned small integer"	,""			,"default '0'"),
			array("menu_headline"			,"unsigned small integer"	,""			,"default '0'"),
			array("menu_images"				,"unsigned small integer"	,""			,"default '1'"),
			array("menu_image_inherit"		,"unsigned small integer"	,""			,"default '1'"),
			array("menu_headline_label"		,"unsigned small integer"	,""			,"default '1'"),
			array("menu_headline_counter"	,"unsigned small integer"	,""			,"default '3'"),
			array("menu_icon"				,"unsigned small integer"	,""			,"default '0'"),
			array("menu_headline_title_pages","unsigned small integer"	,""			,"default '0'"),
			array("menu_external"			,"unsigned small integer"	,""			,"default '0'"),
			array("menu_archiving"			,"unsigned small integer"	,""			,"default '0'"),
			array("menu_archive_on"			,"unsigned small integer"	,""			,"default '0'"),
			array("menu_archive_display"	,"unsigned small integer"	,""			,"default '0'"),
			array("menu_archive_access"		,"unsigned small integer"	,""			,"default '0'"),
			array("menu_archive_label"		,"varchar(255)"				,""			,"default ''"),
			array("menu_archive_page_label"	,"varchar(255)"				,""			,"default ''"),
			array("menu_plus"				,"unsigned small integer"	,""			,"default '0'")
		);
		$primary="menu_identifier";
		$tables[count($tables)] = array("menu_data", $fields, $primary);
		/*
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		* menu_global_commands
		-
		* This table holds commands that users have defined that are to be global ie they 
		* have specified that the mirror is to appear on all menu locations, or the image 
		* rotator.
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		*/
		$fields = array(
			array("mgc_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment"	,"key"),
			array("mgc_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"	,"key"),
			array("mgc_command"		,"varchar(255)"				,""			,"default NULL")
		);
		$primary="mgc_identifier";
		$tables[count($tables)] = array("menu_global_commands", $fields, $primary);
		/*
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		* directory table data
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		*/
		$fields = array(
			array("directory_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment"	,"key"),
			array("directory_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"	,"key"),
			array("directory_parent"		,"integer"					,"NOT NULL"	,"default '-1'"	,"key"),
			array("directory_name"			,"varchar(255)"				,""			,"default NULL"),
			array("directory_can_upload"	,"unsigned small integer"	,""			,"default '1'"),
			array("directory_can_spider"	,"unsigned small integer"	,""			,"default '1'")
		);
		$primary="directory_identifier";
		$tables[count($tables)] = array("directory_data", $fields, $primary);
		/*
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		* menu_sort table data
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		*/
		$fields = array(
			array("menu_sort_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment"	,"key"),
			array("menu_sort_label"			,"varchar(255)"				,""			,"default 'null'"),
			array("menu_sort_tag_value"		,"varchar(255)"				,""			,"default NULL")
		);
		$primary="menu_sort_identifier";
		$sql = Array(
			"insert into menu_sort (menu_sort_label,menu_sort_tag_value) values ('Sort by Page Rank','menu_access_to_page.page_rank');",
			"insert into menu_sort (menu_sort_label,menu_sort_tag_value) values ('Sort by Date Newest First','page_trans_data.trans_date_available desc');",
			"insert into menu_sort (menu_sort_label,menu_sort_tag_value) values ('Sort by Date Oldest First','page_trans_data.trans_date_available asc');",
			"insert into menu_sort (menu_sort_label,menu_sort_tag_value) values ('Sort in Alphabetic order A to Z','page_trans_data.trans_title asc');",
			"insert into menu_sort (menu_sort_label,menu_sort_tag_value) values ('Sort in Alphabetic order Z to A','page_trans_data.trans_title desc');"
			);
		
		$tables[count($tables)] = array("menu_sort", $fields, $primary,$sql);
		/*
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		* directory table data
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		*/
		$fields = array(
			array("display_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment"	,"key"),
			array("display_menu"		,"unsigned integer"			,"NOT NULL"	,"default '0'"	,"key"),
			array("display_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"	,"key"),
			array("display_command"		,"varchar(255)"				,""			,"default ''")
		);
		$primary ="display_identifier";
		$tables[count($tables)] = array("display_data",$fields,$primary);
		/*
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		* directory table data
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		*/
		
		$fields = array(
			array("menu_identifier"		,"unsigned integer"	,"NOT NULL"	,"default '0'"	,"key"),
			array("trans_identifier"	,"unsigned integer"	,"NOT NULL"	,"default '0'"	,"key"),
			array("client_identifier"	,"unsigned integer"	,"NOT NULL"	,"default '0'"	,"key"),
			array("page_rank"			,"integer"			,"NOT NULL"	,"default '0'"),
			array("title_page"			,"small integer"	,"NOT NULL"	,"default '0'")
		);
		$primary ="";
		$tables[count($tables)] = array("menu_access_to_page", $fields, $primary);

		/*
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		* directory table data
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		*/
		
		$fields = array(
			array("mci_menu"		,"unsigned integer"	,"NOT NULL"	,"default '0'"	,"key"),
			array("mci_command"		,"varchar(255)"		,"NOT NULL"	,"default ''"	,""),
			array("mci_client"		,"unsigned integer"	,"NOT NULL"	,"default '0'"	,"key")
		);
		$primary ="";
		$tables[count($tables)] = array("menu_channel_inheritance", $fields, $primary);
		/*
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		* menu_to_object relationship table data
		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		*/
		
		$fields = array(
			array("mto_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment"	,"key"),
			array("mto_menu"		,"unsigned integer"			,"NOT NULL"	,"default '0'"	,"key"),
			array("mto_object"		,"unsigned integer"			,"NOT NULL"	,"default '0'"	,"key"),
			array("mto_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"	,"key"),
			array("mto_module"		,"varchar(255)"				,"NOT NULL"	,"default ''"	,""),
			array("mto_publish"		,"unsigned small integer"	,"NOT NULL"	,"default '1'"	,""),
			array("mto_extract_num"	,"unsigned integer"			,"NOT NULL"	,"default '0'","")
		);
		$primary ="mto_identifier";
		$tables[count($tables)] = array("menu_to_object", $fields, $primary);

		/*************************************************************************************************************************
        * 
        *************************************************************************************************************************/
		$fields = array(
			array("mls_identifier"		,"unsigned integer"			,"NOT NULL"	,"auto_increment"	,"key"),
			array("mls_client"			,"unsigned integer"			,"NOT NULL"	,"default '0'"		,"key"),
			array("mls_module"			,"varchar(255)"				,"NOT NULL"	,"default ''"		,""),
			array("mls_link_id"			,"unsigned integer"			,"NOT NULL"	,"default '0'"		,""),
			array("mls_all_locations"	,"unsigned small integer"	,"NOT NULL"	,"default '0'"		,""),
			array("mls_set_inheritance"	,"unsigned small integer"	,"NOT NULL"	,"default '0'"		,"")
		);
		$primary ="mls_identifier";
		$tables[count($tables)] = array("menu_location_settings", $fields, $primary);
		return $tables;
	}

	function create_client_details($parameters){
		$client_identifier = $this->check_parameters($parameters,"client_identifier",-1);
		/**
		* Table data for menu_data, directory_data and display_data tables 
		* insert new directories, extract directory identifiers, insert menus extract menu 
		* identifiers then insert display data for menus.
		*/
		$sql="insert into directory_data (directory_client, directory_parent, directory_name, directory_can_upload, directory_can_spider) values ($client_identifier,-1,'home',0,0);";
		$this->db->query($sql);
		$sql="insert into directory_data (directory_client, directory_parent, directory_name, directory_can_upload, directory_can_spider) values ($client_identifier,-1,'uploads',1,0);";
		$this->db->query($sql);
		$sql="insert into directory_data (directory_client, directory_parent, directory_name, directory_can_upload, directory_can_spider) values ($client_identifier,-1,'search',0,1);";
		$this->db->query($sql);
//		$sql="insert into directory_data (directory_client, directory_parent, directory_name, directory_can_upload, directory_can_spider) values ($client_identifier,-1,'contact-us',0,1);";
//		$this->db->query($sql);
		$sql="insert into directory_data (directory_client, directory_parent, directory_name, directory_can_upload, directory_can_spider) values ($client_identifier,-1,'site-map',0,1);";
		$this->db->query($sql);

		$sql = "Select * from directory_data where directory_client = $client_identifier";
		$result  = $this->db->query($sql);
		$site_id=-1;
		while ($r = $this->db->fetch_array($result)){
			if ($r["directory_name"]=="search"){
				$search_id = $r["directory_identifier"];
			}
//			if ($r["directory_name"]=="contact-us"){
//				$contact_id = $r["directory_identifier"];
//			}
			if ($r["directory_name"]=="site-map"){
				$site_id = $r["directory_identifier"];
			}
		}
		$sql="insert into menu_data (menu_client, menu_label, menu_url, menu_stylesheet, menu_order, menu_directory) values ($client_identifier, 'Home', 'index.php', 1, 1, 0);";
		$this->db->query($sql);
		$order=2;
		if (($this->parent->server[LICENCE_TYPE]==ECMS) || ($this->parent->server[LICENCE_TYPE]==MECM)){
//			$sql="insert into menu_data (menu_client, menu_label, menu_url, menu_stylesheet, menu_order, menu_directory) values ($client_identifier, 'Administration', 'admin/index.php',2 ,2 ,0);";
//			$this->db->query($sql);
//			$order++;
		}
		$sql="insert into menu_data (menu_client, menu_label, menu_url, menu_stylesheet, menu_order, menu_directory, menu_hidden) values ($client_identifier, 'Search', 'search/index.php', 2, $order, $search_id,0);";
		$this->db->query($sql);
		$order++;
		$sql="insert into menu_data (menu_client, menu_label, menu_url, menu_stylesheet, menu_order, menu_directory, menu_hidden) values ($client_identifier, 'Site Map', 'site-map/index.php', 14, $order, $site_id,0);";
		$this->db->query($sql);

		$sql = "Select * from menu_data where menu_client = $client_identifier";
		$result  = $this->db->query($sql);
		while ($r = $this->db->fetch_array($result)){
			if ($r["menu_url"]=="index.php"){
				$home_id = $r["menu_identifier"];
			}
			if ($r["menu_url"]=="search/index.php"){
				$search_id = $r["menu_identifier"];
			}
//			if ($r["menu_url"]=="contact_us/index.php"){
//				$contact_id = $r["menu_identifier"];
//			}
			if ($r["menu_url"]=="site_map/index.php"){
				$site_id = $r["menu_identifier"];
			}
			/*if ($r["menu_url"]=="admin/index.php"){
				$admin_id = $r["menu_identifier"];
			}*/
		}
		$sql = "insert into display_data (display_client, display_menu, display_command) values ($client_identifier,$home_id,'PRESENTATION_DISPLAY');";
		$this->db->query($sql);
		$sql = "insert into display_data (display_client, display_menu, display_command) values ($client_identifier,$search_id,'PRESENTATION_DISPLAY');";
		$this->db->query($sql);
		$sql = "insert into display_data (display_client, display_menu, display_command) values ($client_identifier,$search_id,'PRESENTATION_SEARCH');";
		$this->db->query($sql);
//		$sql = "insert into display_data (display_client, display_menu, display_command) values ($client_identifier,$contact_id,'PRESENTATION_DISPLAY');";
//		$this->db->query($sql);
//		$sql = "insert into display_data (display_client, display_menu, display_command) values ($client_identifier,$contact_id,'SFORM_DISPLAY_CONTACT_US');";
//		$this->db->query($sql);
		$sql = "insert into display_data (display_client, display_menu, display_command) values ($client_identifier,$site_id,'SITEMAP_DISPLAY');";
		$this->db->query($sql);
		$sql = "insert into display_data (display_client, display_menu, display_command) values ($client_identifier,$site_id,'PRESENTATION_DISPLAY');";
		$this->db->query($sql);
	}
	

}
?>